package com.tian.view.common

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tian.view.BaseRecyclerAdapter
import com.tian.view.R

/**
 * @author tiansongtao, Email:tiansongtao@up366.com
 * @date 2022/12/13 18:12
 */
abstract class BaseListFragment : Fragment() {

    lateinit var mRecyclerView: RecyclerView

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.recycler_view_list, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mRecyclerView = view.findViewById(R.id.rv_list)
        mRecyclerView.layoutManager = LinearLayoutManager(requireContext())
        val adapter = getRecyclerViewAdapter()
        mRecyclerView.adapter = adapter
        adapter.datas = getAdapterData()
    }

    abstract fun getRecyclerViewAdapter(): BaseRecyclerAdapter

    abstract fun getAdapterData(): MutableList<BaseRecyclerAdapter.DataHolder>
}